package org.spring.blog.dao;

import org.spring.blog.pojo.Label;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface LabelDao extends JpaRepository<Label, String>, JpaSpecificationExecutor<Label> {

    @Modifying
    int deleteOneById(String id);


    @Modifying
    @Query(value = "delete from tb_labels where id = ?", nativeQuery = true)
    int customDeleteLabelById(String id);

    Label findOneById(String id);

    Label findOneByName(String _label);


    @Modifying
    @Query(nativeQuery = true, value = "update sob_blog_system.tb_labels set sob_blog_system.tb_labels.count = sob_blog_system.tb_labels.count + 1 where sob_blog_system.tb_labels.name = ?")
    int updateCountByName(String labelName);
}
